
package com.ami.kvm.imageredir;

import com.ami.iusb.RedirProtocolException;
import com.ami.iusb.protocol.RedirHeader;
import com.ami.kvm.jviewer.Debug;
import com.ami.kvm.jviewer.gui.LocaleStrings;
import java.nio.BufferUnderflowException;
import java.nio.ByteBuffer;

public class IUSBHeader extends RedirHeader {
	public static final int IUSB_SIGNATURE_SIZE = 8;
	public static final int IUSB_HEADER_SIZE = 61;
	public static final int HEADER_LEN = 32;
	private static final String IUSB_HEADER = "IUSB    ";
	private static final int IUSB_MAJOR = 1;
	private static final int IUSB_MINOR = 0;
	private byte[] signature;
	private int major;
	private int minor;
	private int headerCheckSum;
	private long dataPacketLen;
	private int serverCaps;
	private int deviceType;
	private int protocol;
	private int direction;
	private int deviceNo;
	private int interfaceNo;
	private int clientData;
	private int instance;
	private long sequenceNo;
	private byte[] key;

	public IUSBHeader(IUSBHeader paramIUSBHeader) {
		setSignature(new byte[8]);
		System.arraycopy(paramIUSBHeader.getSignature(), 0, getSignature(), 0, paramIUSBHeader.getSignature().length);
		setMajor(paramIUSBHeader.getMajor());
		setMinor(paramIUSBHeader.getMinor());
		setHeaderLen(paramIUSBHeader.getHeaderLen());
		setHeaderCheckSum(paramIUSBHeader.getHeaderCheckSum());
		setDataPktLen(paramIUSBHeader.getDataPktLen());
		setServerCaps(paramIUSBHeader.getServerCaps());
		setDeviceType(paramIUSBHeader.getDeviceType());
		setProtocol(paramIUSBHeader.getProtocol());
		setDirection(paramIUSBHeader.getDirection());
		setDeviceNo(paramIUSBHeader.getDeviceNo());
		setInterfaceNo(paramIUSBHeader.getInterfaceNo());
		setClientData(paramIUSBHeader.getClientData());
		setInstance(paramIUSBHeader.getInstance());
		setSeqNo(paramIUSBHeader.getSeqNo());
		setKey(paramIUSBHeader.getKey());
	}

	public IUSBHeader() {
		this.headerLen = 32;
		this.signature = new byte[8];
		this.key = new byte[4];
	}

	public IUSBHeader(int paramInt) {
		this.signature = "IUSB    ".getBytes();
		this.headerLen = 32;
		this.major = 1;
		this.minor = 0;
		this.sequenceNo = 0L;
		this.direction = 128;
		this.dataPacketLen = paramInt;
		this.deviceType = 5;
		this.deviceNo = 0;
		this.interfaceNo = 0;
		this.protocol = 1;
		this.key = new byte[4];
	}

	public IUSBHeader(ByteBuffer paramByteBuffer) {
		byte[] arrayOfByte = new byte[8];
		setSignature(new byte[8]);
		this.key = new byte[4];

		paramByteBuffer.get(arrayOfByte, 0, 8);

		for (int i = 0; i < 8; i++) {
			this.signature[i] = arrayOfByte[i];
		}

		this.major = (paramByteBuffer.get() & 0xFF);

		this.minor = (paramByteBuffer.get() & 0xFF);

		this.headerLen = (paramByteBuffer.get() & 0xFF);

		this.headerCheckSum = (paramByteBuffer.get() & 0xFF);

		this.dataPacketLen = (paramByteBuffer.getInt() & 0xFFFFFFFF);

		this.serverCaps = (paramByteBuffer.get() & 0xFF);

		this.deviceType = (paramByteBuffer.get() & 0xFF);

		this.protocol = (paramByteBuffer.get() & 0xFF);

		this.direction = (paramByteBuffer.get() & 0xFF);

		this.deviceNo = (paramByteBuffer.get() & 0xFF);

		this.interfaceNo = (paramByteBuffer.get() & 0xFF);

		this.clientData = (paramByteBuffer.get() & 0xFF);

		this.instance = (paramByteBuffer.get() & 0xFF);

		this.sequenceNo = (paramByteBuffer.getInt() & 0xFFFFFFFF);

		paramByteBuffer.get(this.key);
	}

	public byte[] getSignature() {
		return this.signature;
	}

	public void setSignature(byte[] paramArrayOfByte) {
		this.signature = paramArrayOfByte;
	}

	public int getMajor() {
		return this.major;
	}

	public void setMajor(int paramInt) {
		this.major = paramInt;
	}

	public int getMinor() {
		return this.minor;
	}

	public void setMinor(int paramInt) {
		this.minor = paramInt;
	}

	public int getHeaderLen() {
		return this.headerLen;
	}

	public void setHeaderLen(int paramInt) {
		this.headerLen = paramInt;
	}

	public int getHeaderCheckSum() {
		return this.headerCheckSum;
	}

	public void setHeaderCheckSum(int paramInt) {
		this.headerCheckSum = paramInt;
	}

	public long getDataPktLen() {
		return this.dataPacketLen;
	}

	public void setDataPktLen(long paramLong) {
		this.dataPacketLen = paramLong;
	}

	public int getServerCaps() {
		return this.serverCaps;
	}

	public void setServerCaps(int paramInt) {
		this.serverCaps = paramInt;
	}

	public int getDeviceType() {
		return this.deviceType;
	}

	public void setDeviceType(int paramInt) {
		this.deviceType = paramInt;
	}

	public int getProtocol() {
		return this.protocol;
	}

	public void setProtocol(int paramInt) {
		this.protocol = paramInt;
	}

	public int getDirection() {
		return this.direction;
	}

	public void setDirection(int paramInt) {
		this.direction = paramInt;
	}

	public int getDeviceNo() {
		return this.deviceNo;
	}

	public void setDeviceNo(int paramInt) {
		this.deviceNo = paramInt;
	}

	public int getInterfaceNo() {
		return this.interfaceNo;
	}

	public void setInterfaceNo(int paramInt) {
		this.interfaceNo = paramInt;
	}

	public int getClientData() {
		return this.clientData;
	}

	public void setClientData(int paramInt) {
		this.clientData = paramInt;
	}

	public int getInstance() {
		return this.instance;
	}

	public void setInstance(int paramInt) {
		this.instance = paramInt;
	}

	public long getSeqNo() {
		return this.sequenceNo;
	}

	public void setSeqNo(long paramLong) {
		this.sequenceNo = paramLong;
	}

	public byte[] getKey() {
		return this.key;
	}

	public void setKey(byte[] paramArrayOfByte) {
		this.key = paramArrayOfByte;
	}

	public void read(ByteBuffer paramByteBuffer) throws RedirProtocolException, BufferUnderflowException {
		paramByteBuffer.get(this.signature);
		String str = new String(this.signature);
		if (!str.equals("IUSB    ")) {
			Debug.out.dump(this.signature);
			throw new RedirProtocolException(LocaleStrings.getString("7_1_IUSBH"));
		}

		this.major = (paramByteBuffer.get() & 0xFF);

		this.minor = (paramByteBuffer.get() & 0xFF);

		this.headerLen = (paramByteBuffer.get() & 0xFF);

		this.headerCheckSum = (paramByteBuffer.get() & 0xFF);

		this.dataPacketLen = (paramByteBuffer.getInt() & 0xFFFFFFFF);

		this.serverCaps = (paramByteBuffer.get() & 0xFF);

		this.deviceType = (paramByteBuffer.get() & 0xFF);

		this.protocol = (paramByteBuffer.get() & 0xFF);

		this.direction = (paramByteBuffer.get() & 0xFF);

		this.deviceNo = (paramByteBuffer.get() & 0xFF);

		this.interfaceNo = (paramByteBuffer.get() & 0xFF);

		this.clientData = (paramByteBuffer.get() & 0xFF);

		this.instance = (paramByteBuffer.get() & 0xFF);

		this.sequenceNo = (paramByteBuffer.getInt() & 0xFFFFFFFF);

		paramByteBuffer.get(this.key);
	}

	public void write(ByteBuffer paramByteBuffer) {
		paramByteBuffer.put(this.signature);
		paramByteBuffer.put((byte) (this.major & 0xFF));
		paramByteBuffer.put((byte) (this.minor & 0xFF));
		paramByteBuffer.put((byte) (this.headerLen & 0xFF));
		paramByteBuffer.put((byte) (this.headerCheckSum & 0xFF));
		paramByteBuffer.putInt((int) (this.dataPacketLen & 0xFFFFFFFF));
		paramByteBuffer.put((byte) (this.serverCaps & 0xFF));
		paramByteBuffer.put((byte) (this.deviceType & 0xFF));
		paramByteBuffer.put((byte) (this.protocol & 0xFF));
		paramByteBuffer.put((byte) (this.direction & 0xFF));
		paramByteBuffer.put((byte) (this.deviceNo & 0xFF));
		paramByteBuffer.put((byte) (this.interfaceNo & 0xFF));
		paramByteBuffer.put((byte) (this.clientData & 0xFF));
		paramByteBuffer.put((byte) (this.instance & 0xFF));
		paramByteBuffer.putInt((int) (this.sequenceNo & 0xFFFFFFFF));
		paramByteBuffer.put(this.key);

		int i = 0;
		for (int j = 0; j < paramByteBuffer.limit(); j++) {
			i = i + (paramByteBuffer.get(j) & 0xFF) & 0xFF;
		}

		paramByteBuffer.put(11, (byte) -(byte) (i & 0xFF));// XXX tianlin 没看懂。。。
	}
}

/*
 * Location:
 * D:\Users\tianlin\Downloads\JViewer.jar!\com\ami\kvm\imageredir\IUSBHeader.
 * class Java compiler version: 5 (49.0) JD-Core Version: 0.7.1
 */